package de.ama.crawler;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import de.ama.util.Util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ama
 * Date: 22.02.11
 * Time: 19:58
 * To change this template use File | Settings | File Templates.
 */
public class Config {

    private String rootdir = new String("");
    private String proxy_host       = new String("");
    private String proxy_port       = new String("");
    private List<String> types      = new ArrayList<String>();
    private List<String> tags       = new ArrayList<String>();

    public String getRootdir()      {     return rootdir;        }
    public String getProxy_host()   {     return proxy_host;     }
    public String getProxy_port()   {     return proxy_port;     }
    public List<String> getTypes()  {     return types;          }
    public List<String> getTags()   {        return tags;        }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////

    private static Config instance = null;
    public static Config get(){
        if(instance==null){
            instance = new Config();

            XStream xstream = new XStream(new DomDriver());
            xstream.alias("config", Config.class);
            xstream.alias("tag", String.class);
            xstream.alias("type", String.class);
            xstream.alias("rootdir", String.class);

            File file = new File("config.xml");
            if(!file.exists()){
                Util.writeXStream(instance , file, xstream);
                System.out.println(file.getAbsolutePath()+" needs params !!!");
                System.exit(0);
            } else {
                instance = (Config) Util.readXStream(instance, file, xstream);
            }
        }
        return instance;
    }

    public File getBinDir(){
        return new File(System.getProperty("user.dir"));
    }

    public File getDataDir(){
        return new File(getBinDir().getParent(),"data");
    }
}
